package yxk.operation;

import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.sdk.plugin.Plugin;
import kd.bos.openapi.common.result.CustomApiResult;
import kd.wtc.wtis.webapi.punchcard.PunchCardApi;
import kd.wtc.wtis.webapi.punchcard.model.PunchCardReqMode;
import kd.wtc.wtis.webapi.punchcard.model.PunchCardRespModel;
import kd.wtc.wtis.webapi.punchcard.validate.ListValidator;
import yxk.task.utils.PunchcardDataUtil;
import yxk.utils.DateUtil;

import java.util.Date;
import java.util.List;

/**
 * 根据选中的时间补海康取卡数据
 * 已废弃
 */
public class CardRetrievalData extends AbstractFormPlugin implements Plugin {
    private static final Log LOG = LogFactory.getLog(CardRetrievalData.class);
    @Override
    public void afterDoOperation(AfterDoOperationEventArgs args){
        String operateKey = args.getOperateKey();
        if("execute".equals(operateKey)){
            Date nwg5_start = (Date) this.getModel().getValue("nwg5_start");
            Date nwg5_end = (Date) this.getModel().getValue("nwg5_end");
            PunchcardDataUtil punchcardDataUtil=new PunchcardDataUtil();
            PunchCardApi api=new PunchCardApi();
            //查询的开始时间和结束时间
            String endStr = DateUtil.getISO8601TimestampFromDateStr(nwg5_end);
            String startStr = DateUtil.getISO8601TimestampFromDateStr(nwg5_start);
            String receiveEndTime = DateUtil.getISO8601TimestampFromDateStr(new Date());
            LOG.info("PunchcardDataHAIKANTask.execute.nwg5_start:{}，nwg5_end：{}",nwg5_start,nwg5_end);
            List<ListValidator<PunchCardReqMode>> haikanPunchcardObtainList = punchcardDataUtil.getHAIKANPunchcardObtainList(startStr,endStr,startStr,receiveEndTime);
            LOG.info("PunchcardDataHAIKANTask.execute.haikanPunchcardObtainList:{}",haikanPunchcardObtainList);
            for (ListValidator<PunchCardReqMode> punchCardReqModes : haikanPunchcardObtainList) {
                CustomApiResult<PunchCardRespModel> punchCardRespModel = api.syncCardRecordService(punchCardReqModes);
                LOG.info("PunchcardDataHAIKANTask.execute.punchCardRespModel:{}",punchCardRespModel);
            }

        }
    }
}